import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

// 创建路由组件
import Home from "@/views/Home.vue";
import User from "@/views/User.vue";
import Main from "@/views/Main.vue";
import Mall from "@/views/Mall.vue";
import PageOne from "@/views/PageOne.vue";
import PageTwo from "@/views/PageTwo.vue";

// 将路由和组件进行映射
const routes = [
    // 主路由
    {
        path: '/',
        component: Main,
        redirect: '/home',
        // 子路由
        children: [
            {
                // 首页
                path: 'home',
                name: 'home',
                component: Home,
            },
            {
                // 用户管理
                path: 'user',
                name: 'user',
                component: User,
            },
            {
                // 商品管理
                path: 'mall',
                name: 'mall',
                component: Mall,
            },
            {
                path: 'page1',
                name: 'page1',
                component: PageOne
            },
            {
                path: 'page2',
                name: 'page2',
                component: PageTwo
            }
        ]
    }

]

// 创建router实例
const router = new VueRouter({
    routes // 缩写，相当于 routes: routes
})

// 暴露实例
export default router;

